

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>ccqw.projectedWidget &mdash; CCQW 0.1.1 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/sidebar.js"></script>
    <link rel="top" title="CCQW 0.1.1 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">CCQW 0.1.1 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for ccqw.projectedWidget</h1><div class="highlight"><pre>
<span class="c"># -*- coding: utf-8 -*-</span>
<span class="sd">&quot;&quot;&quot; A Projected Coordinates Widget</span>

<span class="sd">    :Author:</span>
<span class="sd">      - 20111202-20120110 Roberto Vidmar</span>

<span class="sd">    :Revision:  $Revision: 52 $</span>
<span class="sd">                $Date: 2012-11-12 10:07:15 +0100 (Mon, 12 Nov 2012) $</span>

<span class="sd">    :Copyright: 2011-2012</span>
<span class="sd">                Nicola Creati &lt;ncreati@inogs.it&gt;</span>
<span class="sd">                Roberto Vidmar &lt;rvidmar@inogs.it&gt;</span>

<span class="sd">    :License: MIT/X11 License (see :download:`license.txt</span>
<span class="sd">                               &lt;../../license.txt&gt;`)</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">qtCompat</span> <span class="kn">import</span> <span class="n">Qt</span><span class="p">,</span> <span class="n">QtCore</span><span class="p">,</span> <span class="n">QtGui</span><span class="p">,</span> <span class="n">Signal</span>
<span class="n">QCA</span> <span class="o">=</span> <span class="n">QtCore</span><span class="o">.</span><span class="n">QCoreApplication</span>

<span class="kn">from</span> <span class="nn">abstractFeditor</span> <span class="kn">import</span> <span class="n">UFEditor</span>

<span class="c">#===============================================================================</span>
<div class="viewcode-block" id="ProjectedWidget"><a class="viewcode-back" href="../../ccqw.html#ccqw.projectedWidget.ProjectedWidget">[docs]</a><span class="k">class</span> <span class="nc">ProjectedWidget</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QWidget</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; A Widget that handles projected coordinates</span>
<span class="sd">  &quot;&quot;&quot;</span>
  <span class="n">textEditedSignal</span> <span class="o">=</span> <span class="n">Signal</span><span class="p">(</span><span class="nb">object</span><span class="p">)</span>

<div class="viewcode-block" id="ProjectedWidget.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.projectedWidget.ProjectedWidget.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new instance of the widget.</span>

<span class="sd">        The first argument, if present, is the value to assign.</span>

<span class="sd">        The following keyword arguments are understood:</span>

<span class="sd">        - name      : name of the widget</span>
<span class="sd">                    Default is &#39;&#39;</span>
<span class="sd">        - coordLen  : number of figures in float number</span>
<span class="sd">                    Default is 7</span>
<span class="sd">        - decimals  : number of decmals for the representation</span>
<span class="sd">                    Default is 3</span>
<span class="sd">        - align     : alignment of the widget.</span>
<span class="sd">                    Default is Qt.AlignRight</span>
<span class="sd">        - readonly  : read only attribute.</span>
<span class="sd">                    Default is False</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
      <span class="n">value</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">value</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
      <span class="n">parent</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">parent</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">ProjectedWidget</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">coordLen</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;coordLen&#39;</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">decimals</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;decimals&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">align</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;align&#39;</span><span class="p">,</span> <span class="n">Qt</span><span class="o">.</span><span class="n">AlignRight</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">readonly</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;readonly&#39;</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setObjectName</span><span class="p">(</span><span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">))</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">editor</span> <span class="o">=</span> <span class="n">UFEditor</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">objectName</span><span class="p">())</span>
    <span class="k">if</span> <span class="n">name</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">editor</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjectedWidget&quot;</span><span class="p">,</span>
        <span class="s">&quot;Enter here </span><span class="si">%s</span><span class="s"> in meters.decimals&quot;</span><span class="p">)</span> <span class="o">%</span>
        <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">editor</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjectedWidget&quot;</span><span class="p">,</span>
        <span class="s">&quot;Enter here meters.decimals&quot;</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">editor</span><span class="o">.</span><span class="n">setReadOnly</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">readonly</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">editor</span><span class="o">.</span><span class="n">textEdited</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">textEdited</span><span class="p">)</span>

    <span class="c"># Layout</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_layout</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QVBoxLayout</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_layout</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">editor</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_layout</span><span class="o">.</span><span class="n">setContentsMargins</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">setValue</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ProjectedWidget.textEdited"><a class="viewcode-back" href="../../ccqw.html#ccqw.projectedWidget.ProjectedWidget.textEdited">[docs]</a>  <span class="k">def</span> <span class="nf">textEdited</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Update all widgets except the one that sent the signal</span>

<span class="sd">      :param text: the content of the editor widget</span>
<span class="sd">      :type text: string</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">textEditedSignal</span><span class="o">.</span><span class="n">emit</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sender</span><span class="p">()</span><span class="o">.</span><span class="n">fvalue</span><span class="p">())</span>
</div>
<div class="viewcode-block" id="ProjectedWidget.fvalue"><a class="viewcode-back" href="../../ccqw.html#ccqw.projectedWidget.ProjectedWidget.fvalue">[docs]</a>  <span class="k">def</span> <span class="nf">fvalue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rep</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return widget float value(s) according to rep</span>
<span class="sd">        Default is current representation</span>

<span class="sd">    :param rep: representation **(this parameter is unused)**</span>
<span class="sd">    :type rep: any</span>
<span class="sd">    :returns: widget float value(s) according to rep</span>
<span class="sd">    :rtype: list</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tvalue</span><span class="p">(</span><span class="n">rep</span><span class="p">)]</span>
</div>
<div class="viewcode-block" id="ProjectedWidget.tvalue"><a class="viewcode-back" href="../../ccqw.html#ccqw.projectedWidget.ProjectedWidget.tvalue">[docs]</a>  <span class="k">def</span> <span class="nf">tvalue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rep</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return widget tuple string value according to rep</span>
<span class="sd">        Default is current representation</span>

<span class="sd">    :param rep: representation **(this parameter is unused)**</span>
<span class="sd">    :type rep: any</span>
<span class="sd">    :returns: widget tuple string value according to rep</span>
<span class="sd">    :rtype: tuple</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">editor</span><span class="o">.</span><span class="n">value</span><span class="p">(),</span> <span class="p">)</span>
</div>
<div class="viewcode-block" id="ProjectedWidget.svalue"><a class="viewcode-back" href="../../ccqw.html#ccqw.projectedWidget.ProjectedWidget.svalue">[docs]</a>  <span class="k">def</span> <span class="nf">svalue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rep</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return widget string value according to rep</span>

<span class="sd">        Default is current representation</span>

<span class="sd">    :param rep: representation **(this parameter is unused)**</span>
<span class="sd">    :type rep: any</span>
<span class="sd">    :returns: widget string value according to rep</span>
<span class="sd">    :rtype: tuple</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">editor</span><span class="o">.</span><span class="n">svalue</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="ProjectedWidget.setValue"><a class="viewcode-back" href="../../ccqw.html#ccqw.projectedWidget.ProjectedWidget.setValue">[docs]</a>  <span class="k">def</span> <span class="nf">setValue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Set widget value.</span>

<span class="sd">      :param value: new float value</span>
<span class="sd">      :type value: float</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">editor</span><span class="o">.</span><span class="n">setValue</span><span class="p">(</span><span class="n">value</span><span class="p">)</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/ogs.png" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">CCQW 0.1.1 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Roberto Vidmar, Nicola Creati.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>